home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UUPC11QS.ARJ / CHDIR.C < prev    next >
C/C++ Source or Header  |  1991-11-21  |  3KB  |  75 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    c h d i r . c                                                   */
  3. /*                                                                    */
  4. /*    Support routines for UUPC/extended                              */
  5. /*                                                                    */
  6. /*    Changes Copyright 1990, 1991 (c) Andrew H. Derbyshire           */
  7. /*                                                                    */
  8. /*    History:                                                        */
  9. /*       21Nov1991 Break out of lib.c                          ahd    */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. #include <ctype.h>
  13. #include <dos.h>
  14. #include <direct.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <time.h>
  19.  
  20. /*--------------------------------------------------------------------*/
  21. /*                    UUPC/extended include files                     */
  22. /*--------------------------------------------------------------------*/
  23.  
  24. #include "lib.h"
  25. #include "hlib.h"
  26.  
  27. static int changedir( const char *path);
  28.  
  29. /*--------------------------------------------------------------------*/
  30. /*    C H D I R                                                       */
  31. /*                                                                    */
  32. /*    Like chdir() but create the directory if necessary              */
  33. /*--------------------------------------------------------------------*/
  34.  
  35. int CHDIR(const char *path)
  36. {
  37.  
  38.    if (*path == '\0')
  39.       return 0;
  40.  
  41.    MKDIR(path);
  42.  
  43.    /* change to last directory */
  44.    return changedir(path);
  45.  
  46. } /*CHDIR*/
  47.  
  48. /*--------------------------------------------------------------------*/
  49. /*    c h a n g e d i r                                               */
  50. /*                                                                    */
  51. /*    Like chdir() but also changes the current drive                 */
  52. /*--------------------------------------------------------------------*/
  53.  
  54. static int changedir(const char *path)
  55. {
  56.  
  57.    if ((*path != '\0') && (path[1] == ':')) {
  58.       unsigned char drive = (unsigned char) toupper(*path);
  59.       if ((drive >= 'A') && (drive <= 'Z'))
  60.       {
  61. #ifdef __TURBOC__
  62.          setdisk(drive - (unsigned char)'A');
  63. #else
  64.          if (_chdrive( drive - (unsigned char)'A' + 1))  /* MS C     */
  65.             return -1;                 /* Return if failure          */
  66. #endif
  67.       } /* if */
  68.       else
  69.          return -1;
  70.    }
  71.  
  72.    return chdir(path);
  73.  
  74. } /*changedir*/
  75.